package cn.com.oceansoft.application.listener;

import cn.com.oceansoft.application.Constant;
import cn.com.oceansoft.application.common.spring.SpringContextHolder;
import cn.com.oceansoft.modules.cache.service.BaseCacheService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 系统初始化监听
 *
 * @author chenw
 * @create 16/2/3 16:45
 * @email javacspring@gmail.com
 */
public class SystemInitializer implements ServletContextListener {

    private final Logger logger = LoggerFactory.getLogger(SystemInitializer.class);

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        BaseCacheService cache= SpringContextHolder.getBean("baseCacheService");
        for (int i = 0; i < Constant.count.get(); i++) {
            cache.decr(Constant.ONLINE_NUM);
            String num=cache.get(Constant.ONLINE_NUM);
            if("0".equals(num)){
                return;
            }
        }
    }
}
